package com.chu.advice;

import org.aopalliance.intercept.Joinpoint;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class Advice {

    @Pointcut("execution(* com.chu.controller.*.*(..))")
    public void pointcut(){

    }
    @Before(value = "pointcut()")
    public void before(){
        System.out.println("前置...增强!!！");
    }
    @AfterReturning(value = "pointcut()",returning ="result")
    public void afterReturning(JoinPoint joinpoint, Object result){
        Object target = joinpoint.getTarget();
        System.out.println("被代理对象为："+target);
        System.out.println("后置...增强!!！..返回结果为"+result);
    }
    @Around(value = "pointcut()")
    public void round(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("环绕...前置...增强!!！");
        Object proceed = pjp.proceed();
        System.out.println("环绕...后置...增强!!!");
    }
    @AfterThrowing(value = "pointcut()",throwing = "ex")
    public void exception(Exception ex){
        System.out.println("异常...增强！!!");
    }
    @After(value = "pointcut()")
    public void after(){
        System.out.println("最终...增强！!!");
    }









}
